﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;
using TDDSample;
using TDDSample.Controllers;
using TDDSample.Models;

namespace TDDSample.Tests.Controllers
{
    /// <summary>
    /// Summary description for HomeControllerTest
    /// </summary>
    [TestClass]
    public class HomeControllerTest
    {

        [TestMethod]
        public void HomePage_Renders_HappyNewYear_View_When_Its_NewYear()
        {
            MockRepository mocks = new MockRepository();
            IDateProvider provider =
                mocks.DynamicMock<IDateProvider>();
            using (mocks.Record())
            {
                DateTime day = new DateTime(2008, 1, 1);
                SetupResult.For(provider.GetDate()).Return(day);
            }
            HomeController controller = new HomeController(provider);

            using (mocks.Playback())
            {
                // Act
                ViewResult result = controller.Index() as ViewResult;

                Assert.IsNotNull(result, "A view has not been rendered");
                Assert.AreEqual("HappyNewYear", result.ViewName);
            }
        }

        [TestMethod]
        public void HomePage_Renders_StoreClosed_View_When_Its_Xmas()
        {
            MockRepository mocks = new MockRepository();
            IDateProvider provider =
                mocks.DynamicMock<IDateProvider>();
            using (mocks.Record())
            {
                DateTime xmas = new DateTime(2008, 12, 25);
                SetupResult.For(provider.GetDate()).Return(xmas);
            }
            HomeController controller = new HomeController(provider);

            using (mocks.Playback())
            {

                ViewResult result = controller.Index() as ViewResult;

                Assert.IsNotNull(result, "A view has not been rendered");
                Assert.AreEqual("StoreClosed", result.ViewName);
            }
        }

        [TestMethod]
        public void HomePage_Renders_Index_View_When_Its_Not_Xmas()
        {
            MockRepository mocks = new MockRepository();
            IDateProvider provider =
                mocks.DynamicMock<IDateProvider>();
            using (mocks.Record())
            {
                DateTime xmas = new DateTime(2008, 3, 20);
                SetupResult.For(provider.GetDate()).Return(xmas);
            }
            HomeController controller = new HomeController(provider);

            using (mocks.Playback())
            {

                ViewResult result = controller.Index() as ViewResult;

                Assert.IsNotNull(result, "A view has not been rendered");
                Assert.AreEqual("Index", result.ViewName);
            }
        }

    }
}
